package com.dudy;

import java.util.concurrent.*;

/**
 * @program: zhuguangDemo
 * @description: ${description}
 * @author: dudy
 * @create: 2018-04-03 11:32
 **/
public class ThreadLocalTest {

    private static ThreadLocal<String> threadLocal = new ThreadLocal<String>() {
        @Override
        protected String initialValue() {
            return "test";
        }
    };

    private static class TestThread implements Runnable {

        private int id;

        public TestThread(int id) {
            this.id = id;
        }

        @Override
        public void run() {
            String s = threadLocal.get();
            System.out.println("init threadLocal is " + s);
            s = s + "_" + id;
            threadLocal.set(s);
            System.out.println("after set ,the threadLoal is " + threadLocal.get());
        }
    }

    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(2, 10, 2000, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>());
        for (int i = 0; i < 3; i++) {
            threadPoolExecutor.execute(new TestThread(i));
        }
    }

}
